import os
import config
from subprocess import call

workdir = '/tmp/uit-make'
call('rm -rf %s'%(workdir), shell=True)

paths_tags = config.paths_tags()
for (path, tag) in paths_tags:
	#print '%s %s'% (path,tag)
	folder = os.path.absname(workdir+'/'+tag)
	if not os.path.exists(folder):
		os.makedirs(folder)
	symlink = os.path.absname(folder + '/' + os.path.basename(path))
	#todo check for existance collisions
	os.symlink(path, symlink)

backup = os.path.dirname(config.OUT)+'/.'+os.path.basename(config.OUT)+'.1'
print('backup to %s'%backup)
if os.path.exists(backup):
	call('rm -rf %s'%backup, shell=True)
call('mv -f %s %s > /dev/null 2>&1'%(config.OUT,backup), shell=True)
call('mv -f %s %s'%(workdir,config.OUT), shell=True)
print 'made to %s'%(config.OUT)
